package com.guguju.ssms.feature.splash;

import android.Manifest;
import android.animation.Animator;
import android.animation.ObjectAnimator;

import android.content.Intent;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

import com.google.gson.JsonObject;
import com.guguju.ssms.Guguju;
import com.guguju.ssms.R;
import com.guguju.ssms.bean.LoginData;
import com.guguju.ssms.bean.UserInfo;
import com.guguju.ssms.constant.IntentParms;
import com.guguju.ssms.constant.UrlConstant;
import com.guguju.ssms.core.base.BaseActivity;
import com.guguju.ssms.core.http.BaseResponse;
import com.guguju.ssms.core.http.HttpLoader;
import com.guguju.ssms.core.http.JsonCallback;
import com.guguju.ssms.core.log.LogUtil;
import com.guguju.ssms.feature.Home.HomeActivity;

//import butterknife.BindView;
import okhttp3.Call;
import okhttp3.Response;

public class SplashActivity extends BaseActivity implements SplashContract.View {
    /**
     * 闪屏view
     */
    ImageView ivSplash;

    /**
     * 动画
     */
    ObjectAnimator animator;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        ivSplash=(ImageView)findViewById(R.id.iv_splash);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window w = getWindow(); // in Activity's onCreate() for instance
            w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
        }
       showSplash();

    }


    @Override
    public void doAnimation() {
        animator.setDuration(3000);
        animator.start();
    }

    //private StartUp startUp;


    @Override
    protected void onResume() {
        super.onResume();
        doAnimation();
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        doAnimation();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }


    @Override
    public void showSplash() {
        ivSplash.setImageResource(R.mipmap.splash);
        animator = ObjectAnimator.ofFloat(ivSplash, "alpha", 1f, 1f);
        animator.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(final Animator animator) {
            }

            @Override
            public void onAnimationEnd(final Animator animator) {
                animationEnd();
            }

            @Override
            public void onAnimationCancel(final Animator animator) {
            }

            @Override
            public void onAnimationRepeat(final Animator animator) {
            }
        });
    }

    /**
     * 动画结束后的操作
     */
    private void animationEnd() {
        Intent intent = new Intent(SplashActivity.this, HomeActivity.class);
        intent.putExtra(IntentParms.HOME_FRAGMENT_TYPE, HomeActivity.FRAGMENT_INDEX);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
    }







}
